<?php
require_once(dirname(__FILE__).'/../include/config.inc.php');
header('Content-type: application/json;charset=utf-8');
$url="https://w.url.cn/s/AdO9Mr6";
$true_url="http://hty.hnbest.com";
$filename="AdO9Mr6";

$txt_name=dirname(__FILE__)."/../checkdomain/".$filename.".txt";
if(file_exists($txt_name))
{
	exit();
}

if(isset($url)){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, 1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
	//curl_setopt($ch, CURLOPT_POST, 1);
	//curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
	$html = curl_exec($ch);
	var_dump($html);
	$num=strpos($html,'weixin110.qq.com');
	if($num){
		$time=date("Y-m-d H:i:s",time());
		$txt_name=dirname(__FILE__)."/../checkdomain/".$filename.".txt";
		file_put_contents($txt_name,$html."\n".$url."\n".$true_url);		

		/* 发送消息 */
		require_once "WxApi.php";
		require_once "WxConfig.php";
		require_once(dirname(__FILE__).'/../jssdk.php');
		$appId=WxConfig::APPID;
		$appSecret=WxConfig::APPSECRET;
		$jssdk = new JSSDK($appId, $appSecret);
		$g_AccessToken=$jssdk->getAccessToken();
		$open_arr=array('oB8ZK1AS39XvcBhM8me8WRYfHN7s','oB8ZK1Hd3BHjTjQJ4p61Utom9pao');
		//$open_arr=array('oB8ZK1AS39XvcBhM8me8WRYfHN7s');
		foreach ($open_arr as $key => $value) {
			if(isset($g_AccessToken)){
				//封装为json格式的数据
				$json='{
				  "touser": "'.$value.'" ,  
				  "template_id": "cjXcmmMtT6yP5OJ99k8KirHq6D4H6Rv_LwhrQOgIJcI",    
				  "url":"'.$true_url.'",         
				  "data": {
						  "first": {
							  "value": "您好，网络故障，请及时处理！", 
							  "color": "#f71b03"
						  }, 
						  "keyword1": {
							  "value": "'.$time.'", 
							  "color": "#173177"
						  }, 
						  "keyword2": {
							  "value": "网页被暂停", 
							  "color": "#173177"
						  },
						  "remark": {
							  "value": "故障页面:'.$true_url.'请点击查看详情", 
							  "color": "#f71b03"
						  } 
				  }
				}';
				sendWxMsg($json);
			}
		}
		

	}
	
}



// json 为json格式的数据

function sendWxMsg($json){
	//发送消息
	global $g_AccessToken,$filename;
	if(isset($g_AccessToken)){
		$uuu="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$g_AccessToken;
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $uuu);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  //https协议
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
		$html = curl_exec($ch);

	}

}